<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ taglib prefix="d" uri="http://dgg.net/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <title>已放款明细列表数据</title>
    <c:import url="../../header.jsp"/>
</head>
<body>
<div class="content-warp">
    <div class="dgg-list-top-warp">
        <div class="screen-search">
            <ul>
                <li>
                    <label>放款日期：</label>
                    <input type="text" readonly class="dggui-input dggui-time-range" id="loanTime" name="loanTime">
                    <i class="iconfont icon-rili"></i>
                </li>
                <li>
                    <label>生产部门：</label>
                    <input type="text" class="dggui-input" id="flowUserDep" data-id="" value=""  style="min-width: 320px;"   />
                </li>
                <li>
                    <label>业务类型：</label>
                    <input type="hidden" name="typeCodeHidden" id="typeCodeHidden">
                    <div name="typeCode" id="typeCode"></div>
                </li>
                <li>
                    <label>流程人员：</label>
                    <select id="flowUserId" name="flowUserId" style="min-width: 80px; display: none;">
                    </select>
                </li>
                <li>
                    <button class="dggui-btn searchBtn" >搜索</button>
                    <button class="dggui-btn dggui-btn-primary" onclick="cleanSearch();return false;">清空条件</button>
                    <d:hasUrlAuth authCode="RZSC_OPERATION_EXPORT">
                        <button class="dggui-btn dggui-btn-green"
                                onclick="excelExportProductDetailed('${basePath}/rzsc/detatil/excel_export_product_detatil.do');return false;">导出
                        </button>
                    </d:hasUrlAuth>
                </li>
            </ul>

        </div>
    </div>
    <div class="list-content">
        <div class="table-warp">
            <table class="dggui-table" id="loanDetatil">
            </table>
        </div>
    </div>
</div>

<c:import url="/WEB-INF/jsp/footer.jsp"/>
<script>
    var tables;
    dggui.use(['table', 'select2', 'distpicker', 'dggdate','droptree'], function () {
        var table = dggui.table;
        var select2 = dggui.select2;
        var distpicker = dggui.distpicker;
        var dggdate = dggui.dggdate;
        var droptree = dggui.droptree;
        // 获取当前月1号和当天。currMonth前月1号，currDate当天
        var dateRange= getTime();
        $("#loanTime").val(dateRange);

        //初始化业务类型及产品
        distpicker.render({
            url: "${basePath}/rzsc/common/tree_book_list.do?code=BUS_YT_DK&type=2&level=2", // 请求地址
            elem: '#typeCode', // 容器Id
            type: 2,
            placeholder: '选择业态',
            defaultParentCode: 'BUS_YT_DK',
            callback: function () {//如果不需要选产品就把callback整个方法注释掉
                var code = $("#typeCode .plug-in-code").val();
                initProductCode("#productCode", code);
                select2.render({
                    placeholder: "请选择",
                    allowClear: true,
                    elem: $('#productCode'),
                    width: "160px"
                });
                var produtId = $("#productCode").val();
                initChannel("#channelCode", produtId);
                select2.render({
                    placeholder: "请选择",
                    allowClear: true,
                    elem: $('#channelCode'),
                    width: "160px"
                });
            },
            callbackClear: function () {
                $("#productCode").find("option").remove();
                $("#productCode").append("<option value=''>请选择</option>");
                $("#channelCode").find("option").remove();
                $("#channelCode").append("<option value=''>请选择</option>");
            }
        });

        //初始化流程人员
        initUser("RZSC_FLOW_USER", "role", "#flowUserId");
        select2.render({
            placeholder: "请选择",
            allowClear: true,
            elem: $('#flowUserId'),
            width: "160px"
        });
        //初始化放款时间
        dggdate.render({
            elem: '#loanTime',
            type: 'date',
            range: '~', //或 range: '~' 来自定义分割字符
            value: dateRange,
            isInitValue: true
        });
        //初始化放款时间
      /*  dggdate.render({
            elem: '#loanTimeEnd',
            type: 'date',
            value: dateArry.currDate,
            isInitValue: true
        });*/
        queryAllDep("#flowUserDep");
        var opt = {
            "elem": "#loanDetatil",
            "ajax": sysInfo.basePath + "/rzsc/detatil/loan_detatli_data.do",
            "scrollX": "true",//是否开启横项滚动
            //"selectCheck": false, //多选,同时选中复选框
            "oneSelectCheck": true,//单选，同时选中复选框
            "visible": true,
            "fnServerParams": function (aoData) {
                //搜索条件
                aoData = $.extend(aoData, {
                        flowUserDep: $("#flowUserDep").attr("data-id"),
                        flowUserId: $("#flowUserId").val(),
                        typeCode:$("#typeCode .plug-in-code").val(),
                        loanTime: $("#loanTime").val(),
                    }
                )
                console.log(aoData);
                return aoData;

            },
            "aoColumns": [
                {
                    "title": "接单日期",
                    "data": "receiveOrderDate",
                    "orderable": false,
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title": "放款日期",
                    "data": "loanTime",
                    "orderable": false,
                    "render": function (data, type, full, meta) {
                        var dataFormat
                        if (checkEmpty(data)) {
                            dataFormat= new Date(data).format("yyyy-MM-dd");
                        }else {
                            dataFormat='';
                        }
                        return dataFormat ? dataFormat : '';
                    }
                },
                {
                    "title": "客户姓名",
                    "orderable": false,
                    "data": "customerName",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title": "签单人部门",
                    "orderable": false,
                    "data": "signUserOrgName",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title": "签单商务",
                    "orderable": false,
                    "data": "signUserName",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title": "生产所属事业部",
                    "orderable": false,
                    "data": "productOrgName",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title": "流程人员部门",
                    "orderable": false,
                    "data": "flowUserOrgName",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title": "流程人员",
                    "orderable": false,
                    "data": "flowUserName",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },

                {
                    "title": "生产状态",
                    "orderable": false,
                    "data": "status",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title": "业务类型",
                    "orderable": false,
                    "data": "businessProductName",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title": "产品名称",
                    "orderable": false,
                    "data": "productName",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title": "商品属性",
                    "orderable": false,
                    "data": "goodsName",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title": "渠道",
                    "orderable": false,
                    "data": "channelName",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title":"利息",
                    "orderable": false,
                    "data": "orderLoansInterest",
                    "render": function (data, type, full, meta) {
                        var txt= '';
                        if (data != '' && data != null) {
                            txt = data + "%";
                        }
                        return txt ? txt : '';
                    }
                },
                {
                    "title": "还款方式",
                    "orderable": false,
                    "data": "wayOfLoan",
                    "render": function (data, type, full, meta) {
                        var txt = loanWayTranslate(data);
                        return txt ? txt : '';
                    }
                },
         /*       {
                    "title": "客户经理",
                    "orderable": false,
                    "data": "relationshipManager",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },*/
                {
                    'title': '需求金额',
                    'data': "money",
                    "orderable": false,
                    "render": function (data, type, row, meta) {
                        return data ? data : '';
                    }
                },
                {
                    'title': '放款金额',
                    'data': "loanAmount",
                    "orderable": false,
                    "render": function (data, type, row, meta) {
                        return data ? data : '';
                    }
                },
                {
                    'title': '放款时长',
                    'data': "loanTimeDay",
                    "orderable": false,
                    "render": function (data, type, row, meta) {
                        return data ? data : '';
                    }
                },
                {
                    'title': '还款时间',
                    'data': "dateOfLoan",
                    "orderable": false,
                    "render": function (data, type, row, meta) {
                        return data ? data : '';
                    }
                },
                {
                    'title': '到期日',
                    'data': "repaymentDate",
                    "orderable": false,
                    "render": function (data, type, row, meta) {
                        var dataFormat
                        if (checkEmpty(data)) {
                            dataFormat= new Date(data).format("yyyy-MM-dd");
                        }else {
                            dataFormat='';
                        }
                        return dataFormat ? dataFormat : '';
                    }
                },
                {
                    'title': '合同编号',
                    'data': "contractNo",
                    "orderable": false,
                    "render": function (data, type, row, meta) {
                        return data ? data : '';
                    }
                },
            ]
        };
        tables=table.render(opt);
        $('.searchBtn').click(function (){
            tables.ajax.reload();

        })
        // 处理dataTable 异常错误信息
        $.fn.dataTable.ext.errMode = 'none';//不抛出异常
        tables.on('error.dt', function (e, settings, techNote, message) {
            //dggui.dialog.errors("表格查询错误，请联系管理员", 2000);
            if (checkEmpty(settings.jqXHR.responseJSON.error)) {
                dggui.dialog.errors(settings.jqXHR.responseJSON.error, 2000);
            }
        });
    });

    //列表刷新
    function tableReload() {
        var moneyMax = $("#moneyMax").val().trim();
        var moneyMin = $("#moneyMin").val().trim();
        if (!checkMoneySearch(moneyMin, moneyMax)) {
            return false;
        }
        tables.ajax.reload();
    }


    /**
     * 导出
     * */
    function excelExportProductDetailed(url) {
        var obj = new Object();
        obj.flowUserDep= $("#flowUserDep").attr("data-id");
        obj.flowUserId= $("#flowUserId").val();
        obj.typeCode=$("#typeCode .plug-in-code").val();
        obj.loanTime=$("#loanTime").val();
        formSubmit(url, obj);
    }

    //还款方式
    function loanWayTranslate(way) {
        var txt = "";
        switch (way) {
            case "1" :
                txt = "分期还款";
                break;
            case "2" :
                txt = "其他";
                break;
            case "3" :
                txt = "先息后本";
                break;
            case "4" :
                txt = "等额等息";
                break;
            case "5" :
                txt = "等额本金";
                break;
            case "6" :
                txt = "等本等息";
                break;
            case "7" :
                txt = "减本减息";
                break;
            case "8" :
                txt = "计划归还";
                break;
        }

        return txt;
    }
</script>
</body>
</html>